#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    int n, k;
    cin >> n >> k;
    
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    ll res = 0;
    vector<pair<ll, ll>> xy;
    
    for (int i = 0; i < n; ++i) {
        ll ai = a[i];
        ll bi = b[i];
        ll yi = abs(ai - bi);
        res += yi;
        xy.emplace_back(ai + bi, yi);
    }
    
    sort(xy.begin(), xy.end());
    
    ll mn = 0x3f3f3f3f;
    for (int i = 0; i < n - 1; ++i) {
        ll xi = xy[i].first;
        ll yi = xy[i].second;
        ll xj = xy[i+1].first;
        ll yj = xy[i+1].second;
        
        ll d = (xj - xi) - (yi + yj);
        
        mn=min(d>0?d:0,mn);
    }
    
    if (k == 0) {
        cout << res << '\n';
    } else {
        cout << res + mn << '\n';
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}